//
//  MainWindow.h
//  GameJam-Mac
//
//  Created by Sin Clover on 12/7/11.
//  Copyright 2011 Snow Poem Society. All rights reserved.
//

#include "stdafx.h"
#include "MainController.h"

#include "Editor/AEUIManager.h"
#include "Editor/AEUtility.h"

MainController* MainController::s_MainController = NULL;

MainController::MainController(): 
    _infoLabel(NULL)
{	
	// We must set the sound callback method.  Although, I'm wondering if we should 
	// allow them to not specify it if they don't need the functionality.
	theSound.SetSoundCallback(this, &GameManager::SoundEnded);
    
    
    // Test of using the ui system, simple button and label.
    
    AEDelegate d = AEDelegate::from_method<MainController, &MainController::Foo>(this);
    _displayText = "You clicked ";
    
    AEButton* button1 = theUIManager.addButton(Vector2(160.0f, 80.0f), d);
    AEButton* button2 = theUIManager.addButton(Vector2(160.0f, 150.0f), d);
    AEButton* button3 = theUIManager.addButton(Vector2(160.0f, 220.0f), d);
    AEButton* button4 = theUIManager.addButton(Vector2(160.0f, 290.0f), d);
    
    button1->setText("Button 1");
    button2->setText("Button 2");
    button3->setText("Button 3");
    button4->setText("Button 4");
    
    _infoLabel = theUIManager.addLabel(Vector2(480.0f, 200.0f), "You have not clicked any buttons.");
}

MainController& MainController::GetInstance()
{
	if (s_MainController == NULL)
	{
		s_MainController = new MainController();
	}
	return *s_MainController;
}

void MainController::Foo(AEControl *sender)
{
    String text;
    AEButton* button = dynamic_cast<AEButton*>(sender);
    if (button)
    {
        text = _displayText + button->getText();
    }
    
    _infoLabel->setText(text);
}

